<?php
namespace Admin\Controller;
use Think\Controller;
class MessageController extends Controller {
    // 后台登录页
    public function index(){
        if(isset($_SESSION['admin'])){
            $message = D('message');
            $messageList = $message->order('id desc')->select();
            $this->assign('messageList',$messageList);
            $this->display();
            
        }else{
            $url = 'http://localhost/book-order/index.php/Admin/Index/manage';
            header("location: $url");
        }
    }
 
 
//删除留言
    public function messageDelete(){
        $id = $_POST['id'];
        $message = D('message');
        $data['state'] = 1;        
        //$success = $project->where("id='$id'")->delete();
        $success = $message->where("id='$id'")->delete($data);
        if($success){
            $result = array(
                'code'=> '0',
                'ext'=> 'success'
            );
            echo json_encode($result);
        }else {
            $result = array(
                'code'=> '1',
                'ext'=> 'fail'
            );
            echo json_encode($result);
        }
    }
//刷列表
    public function messageList(){
        $message = D('message');
        $resultArr = $message->select();
        //echo json_encode($resultArr,JSON_UNESCAPED_UNICODE);
        echo json_encode($result);
    }

}
